Now, Redis can work with m-s stretegy.
But, The questions is that what will happen when the master crashes?
can redis slave turn to be a role of master and continue the service?
The answer is definitly yes. what we need is just the plugin software called
sentinel that packeted into redis since version 2.5.12. Although, the 2.5.12
version has already support this feature, I still recommand to use the 2.8.19,
for it’s stable.
First, copy the config file into the path /opt/redis/etc/
cp /opt/software/redis-2.8.19/sentinel.conf /opt/redis/etc/redis_sentinel.conf
create the required path:
mkdir -p /opt/redis/sentinel
mkdir -p /opt/redis/data/redis_7380/
Then, edit the config file as the following:
###################### sentinel main config ######################
daemonize yes # run background
pidfile “/opt/redis/run/redis-sentinel.pid” # pid path
port 26379
#sentinel announce-ip <ip>
#sentinel announce-port <port>
# loglevel <level> debug, verbose, notice, warning
loglevel notice
logfile “/data/redis/log/redis-sentinel.log”
dbfilename “sentinel.rdb”
dir “/opt/redis/sentinel”
################# sentinel server group ##################
sentinel monitor mymaster 127.0.0.1 6379 1
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 30000
sentinel notification-script mymaster /opt/redis/bin/notify.sh
sentinel client-reconfig-script mymaster /opt/redis/bin/reconfig.sh
Just config, we’ll talk about what all the options means later.
Next, save and start sentinel service:
/opt/redis/bin/redis-sentinel /opt/redis/etc/redis_sentinel.conf
or
/opt/redis/bin/redis-server /opt/redis/etc/redis_sentinel.conf –sentinel
check the result using “ps -ef | grep redis”
Last, do some test:
/opt/redis/bin/redis-cli -p 6379 shutdown
/opt/redis/bin/redis-cli -p 7379 info Replication
If it shows “role:master”, means the sentinel service installed and configured success.
OK, do some more start & restart, then check if the switch works well.